package main

import (
	"crypto/md5"
	"encoding/hex"
	"fmt"
	"github.com/anaskhan96/go-password-encoder"
	"io"
	"mxshop/user_srv/global"
	"mxshop/user_srv/model"
	"strings"
)

func main() {
	global.DB.AutoMigrate(&model.User{})
	var total int64
	result := global.DB.Model(&model.User{}).Count(&total)
	fmt.Println(result)
	fmt.Println(total)

	options := &password.Options{10, 1000, 30, md5.New}
	salt, encodedPwd := password.Encode("generic password", options)
	newPassword := fmt.Sprintf("$sssss$%s$%s", salt, encodedPwd)
	passwordInfo := strings.Split(newPassword, "$")
	fmt.Println(passwordInfo)
	check := password.Verify("generic password", passwordInfo[2], passwordInfo[3], options)
	fmt.Println(check) // true

}

func getMd5(code string) string {
	MD5 := md5.New()
	io.WriteString(MD5, code)
	return hex.EncodeToString(MD5.Sum(nil))
}
